#include "TraceDebug.h"
#include "RingBuffer.h"

#include <iostream>

void TestRingBuffer()
{
	std::string inputStr;
	RingBuffer* pRb = new RingBuffer(20);
	while(1)
	{
		TRACE_YELLOW("========RingBuffer Test===========\n");
		TRACE_YELLOW("quit/q ---> quit test.\n");
		TRACE_YELLOW("01 ---> push.\n");
		TRACE_YELLOW("02 ---> pop.\n");
		TRACE_YELLOW("03 ---> clear.\n");
		TRACE_YELLOW("=====================================\n");
		std::cin >> inputStr;
        std::cout << inputStr<<std::endl;
		if("01" == inputStr)
		{
			sint32 len =pRb->push("123456789", 9);
			if(len==STATUS_ERROR)
			{
				TRACE_ERR("RingBuffer push error.\n");
			}
			else if(len<9)
			{
				TRACE_ERR("RingBuffer is full!\n");
			}
		}
		else if("02" == inputStr)
		{
			char buf[7]={0};
			sint32 len=pRb->pop(buf,7);
			if (len>0)
			{
				TRACE_HEX("ringbuf_pop", buf, len);
			}
			else
			{
				TRACE_ERR("RingBuffer pop error.\n");
			}
		}
		else if("03" == inputStr)
		{
			pRb->clear();
		}
		else if("q" == inputStr || "quit" == inputStr)
		{
			return;
		}
		inputStr.clear();
	}
}